package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("seller")
public class SellerController {

    @Reference
    private SellerService sellerService;

    @RequestMapping("show")
    public String show(){
        return "admin/seller";
    }

    @RequestMapping("sellerList")
    @ResponseBody
    public Result sellerList(TbSeller tbSeller){
        try{
            List<TbSeller> list = sellerService.sellerList(tbSeller);
            return Result.response(ResultEnum.SUCCESS).setData(list);
        }catch (Exception e){
            return Result.response(ResultEnum.ERROR).setData(e);
        }
    }

    @RequestMapping("getMessage")
    @ResponseBody
    public Result getMessage(String sellerId){
        try{
            TbSeller list = sellerService.getMessage(sellerId);
            return Result.response(ResultEnum.SUCCESS).setData(list);
        }catch (Exception e){
            return Result.response(ResultEnum.ERROR).setData(e);
        }
    }
    //商家管理
    @RequestMapping("update")
    @ResponseBody
    public Result update(TbSeller tbSeller){
        try{
            Integer i = sellerService.update(tbSeller);
            return Result.response(ResultEnum.SUCCESS).setData(i);
        }catch (Exception e){
            return Result.response(ResultEnum.ERROR).setData(e);
        }
    }


}
